﻿@{
    ViewBag.Title = "ContentIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var _Category = request('Category');
    var organizeId = request('organizeId');
    $(function () {
        GetGrid();
    });

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = new Object();
        queryJson["organizeId"] = organizeId;
        queryJson["Category"] = _Category;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "/DailyEventManage/OpenShop/GetContent",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 70, align: "center" },
                { label: "名称", name: "Name", index: "Name", width: 100, align: "center" },
                {
                    label: "类型", name: "Type", index: "Type", width: 50, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 0 ? "录入型" : "选择型";
                    }
                },
                { label: "内容详情", name: "Type", index: "Type", width: 100, align: "center", hidden: true },
                {
                    label: "是否必填", name: "IsNeed", index: "IsNeed", width: 80, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == 1 ? "<i value=" + cellvalue + " class=\"fa fa-toggle-on\"></i>" : "<i value=" + cellvalue + " class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: "说明", name: "Memo", index: "Memo", width: 150, align: "left" }
            ],
            rownumbers: true,
            rowNum: 1000,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            ondblClickRow: function (rowid, iRow, iCol, e) {
                var obj = $("#" + this.id).getRowData(rowid);
                obj["ObjectTypeId"] = _ObjectTypeId;
                obj["ObjectTypeName"] = _ObjectTypeName;
                $('#gridTable1').addRowData(_rowid, obj);
                _rowid++;
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            var queryJson = new Object();
            queryJson["organizeId"] = organizeId;
            queryJson["Category"] = _Category;
            queryJson["keyword"] = $("#txt_Keyword").val();
            $gridTable.jqGrid('setGridParam', {
                url: "../../DailyEventManage/OpenShop/GetObject",
                postData: { queryJson: JSON.stringify(queryJson) }
            }).trigger('reloadGrid');
        });
        //查询回车
        $('#txt_Keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "ContentForm",
            title: '添加内容',
            url: '/DailyEventManage/OpenShop/ContentForm?Category=' + _Category,
            width: "800px",
            height: "520px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "ContentForm",
                title: '编辑内容',
                url: '/DailyEventManage/OpenShop/ContentForm?keyValue=' + keyValue + "&Category=" + _Category,
                width: "800px",
                height: "520px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "/DailyEventManage/OpenShop/RemoveContentForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的内容！', 0);
        }
    }
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td style="padding-left: 2px;">
                                <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要名称或者编号" style="width: 200px;" />
                            </td>
                            <td style="padding-left: 5px;">
                                <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-addContent" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-editContent" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-deleteContent" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
            </div>
        </div>
    </div>
</div>
